function spinalCase(str) {
    function replacer(match) {
        return ' ' + match;
    }

    if (str[0] <= 'z' && str[0] >= 'a') {
        str = str.replace(/[A-Z]+/g, replacer);
    }
    str = str.replace(/\s/g, '-').replace(/_/g, '-').toLowerCase();
    return str;
}

console.log(spinalCase('This Is Spinal Tap'));

